<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <meta charset="UTF-8">
    <title>代办事项</title>
    <link rel="stylesheet" type="text/css" media="screen" href="../../css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="../../css/dataTables.bootstrap.min.css">
    <link rel="stylesheet" href="../../layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="../../css/global.css" media="all"/>
    <style>
        .layui-disabled {
            color: #0C0C0C !important;
        }
    </style>
</head>
<body style="overflow: auto">
<div class="panel-page">
    <div class="top-box">
        <span id="dtTitle" style="text-align:center"></span>
    </div>
    <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
        <form class="layui-form form-container" lay-filter="scoreRuleForm" style="width: 1100px;margin: 0 auto"
              action="">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">巡察单位</label>
                    <div class="layui-input-inline">
                        <select name="branch" lay-filter="branch" class="xg" id="branch" lay-search
                                lay-verify="required">
                            <option value=""></option>
                        </select>
                    </div>

                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">审核人</label>
                    <div class="layui-input-inline">
                        <select name="reviewer" id="reviewer" lay-verify="required" lay-filter="xmFilter" class="xg">
                        </select>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">

                <div class="layui-inline">
                    <label class="layui-form-label">巡察年度</label>
                    <div class="layui-input-inline">
                        <select name="year" id="year" lay-verify="required" lay-filter="xmFilter" class="xg">
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">问题类别</label>
                    <div class="layui-input-inline">
                        <select name="questionType" id="questionType" lay-verify="required" lay-filter="xmFilter"
                                class="xg">
                        </select>
                    </div>
                </div>

            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">问题来源</label>
                    <div class="layui-input-inline">
                        <select name="sourceProblem" id="sourceProblem" lay-verify="required" class="xg"
                                lay-filter="xmFilter">
                            <option value=""></option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">问题项</label>
                <div class="layui-input-block" style="margin-left: 150px;width: 740px">
                    <textarea placeholder="请输入问题项" maxlength="100" id="question" name="question"
                              class="layui-textarea xg"
                              style="height: 100px"></textarea>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">问题描述</label>
                <div class="layui-input-block" style="margin-left: 150px;width: 740px">
                    <textarea placeholder="请输入问题描述" name="questionDetail" id="questionDetail" class="layui-textarea xg"
                              style="height: 150px"></textarea>
                </div>
            </div>


            <!--审核-->
            <div class="layui-form-item sh">
                <label class="layui-form-label">审核意见</label>
                <div class="layui-input-block" style="margin-left: 150px;width: 740px">
                    <textarea placeholder="请输入内容" id="auditOpinion" name="auditOpinion"
                              class="layui-textarea" style="height: 10px"></textarea>
                </div>
            </div>


            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="button" class="layui-btn save" lay-submit lay-filter="saveBtn" id="btn1">提交</button>

                    <button type="button" class="layui-btn" id="btn2">上传附件</button>


                    <button class="layui-btn agree" lay-submit lay-filter="agreeBtn" id="btn4">同意</button>
                    <button class="layui-btn disagree" lay-submit lay-filter="notAgreeBtn" id="btn5">不同意</button>

                </div>
            </div>
        </form>

        <div class="outer-page-inner">
            <div class="title-container shjl">
                审核记录
                <i class="layui-icon layui-icon-up"></i>
            </div>
            <div class="widget-body no-padding shjl">
                <table id="records" class="table table-striped table-bordered table-hover" style="width:100%">
                    <thead>
                    <tr>
                    </tr>
                    <tr>
                        <th style="display: none">id</th>
                        <th width="200px">审核状态</th>
                        <th width="200px">录入时间</th>
                        <th width="200px">操作人员</th>
                        <th>审核意见</th>
                    </tr>
                    </thead>
                    <tbody>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<!--附件下载-->
<div id="hidden1" lay-filter="hidden1" style="display: none">
    <table id="department_result" lay-filter="department_result"></table>
</div>

<script type="text/html" id="hidden1-table-tool">
    <a class="layui-btn layui-btn-xs" lay-event="select">选择</a>
</script>

<div id="openProductBox" style="display: none; padding: 10px;">
    <table id="openProductTable" lay-filter="openProductTable"></table>
</div>
<div id="openProductBox2" style="display: none; padding: 10px;">
    <button type="button" lay-event="del" class="layui-btn layui-btn-sm" id="down"><i class="layui-icon"></i>查看附件</button>
    <table class="layui-hide" id="test" lay-filter="test"></table>
</div>

<script type="text/html" id="itemTpl">
    {{# if( d.type == 2 && d.delated == 0){ }}
    <button type="button" lay-event="del1" class="layui-btn layui-btn-sm" id="del1"><i class="layui-icon"></i>删除
    </button>
    {{# } }}

    {{# if( d.type == 3 && d.delated == 1){ }}
    <button type="button" lay-event="del2" class="layui-btn layui-btn-sm" id="del2"><i class="layui-icon"></i>删除
    </button>
    {{# } }}
</script>

<script type="text/javascript" src="../../js/libs/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="../../js/jq.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/dataTables.bootstrap.min.js"></script>
<script type="text/javascript" src="../../layui/layui.js"></script>
<script type="text/javascript" src="../../js/my/permission.js"></script>
<script type="text/javascript">

    //获取url后的参数值
    function getUrlParam(key) {
        var href = window.location.href;
        var url = href.split("?");
        if (url.length <= 1) {
            return "";
        }
        var params = url[1].split("&");

        for (var i = 0; i < params.length; i++) {
            var param = params[i].split("=");
            if (key == param[0]) {
                return param[1];
            }
        }
    }

    // 查看附件
    $("#btn3").click(function () {
        layui.use(['table', 'form'], function () {
            var table = layui.table;

            var id = getUrlParam("id");
            var form = layui.form;
            if (id.length > 0) {
                layer.open({
                    type: 1,
                    title: '附件列表',
                    area: ['80%', '80%'], //宽高
                    content: $('#openProductBox2'),
                    success: function (data) {
                        table.render({
                            elem: '#test'
                            , width: '100%'
                            , method: 'post' //接口http请求类型，默认：get
                            , page: false
                            , limit: Number.MAX_VALUE
                            , url: '/mOverseeQuestions/fileList?id=' + id //?page=1&limit=10（该参数可通过 request 自定义）

                            , cols: [[
                                {
                                    type: 'checkbox'
                                },
                                {
                                    field: 'id', //字段名
                                    title: '序号', //标题
                                    width: 100
                                }, {
                                    field: 'branch', //字段名
                                    title: '单位名称', //标题
                                    width: 200
                                    //fixed: 'left' //固定列
                                }, {
                                    field: 'question', //字段名
                                    title: '问题项', //标题
                                    width: 200
                                }, {
                                    field: 'path', //字段名
                                    title: '附件名称', //标题
                                    width: 580
                                }, {
                                    field: '', title: '操作',
                                    width: 114,
                                    toolbar: '#itemTpl',
                                    fixed: 'right' //固定列
                                }
                            ]]
                        });
                    }
                });
            }
        });
        layui.use('table', function () {
            var table = layui.table;
            //监听行工具事件
            table.on('tool(test)', function (obj) {
                var checkStatus = layui.table.checkStatus('openProductBox2').data;
                var data = obj.data;
                console.log(data)
                if (obj.event === 'del') {
                    var s = data.path;
                    location.href = '/mOverseeQuestions/downSource?path=' + s;
                }
                if (obj.event === 'del1') {
                    var id = data.id;
                    $.ajax({
                        url: '/mOverseeQuestions/deletePathOne?id=' + id,
                        type: 'get',
                        success: function () {
                            layer.msg("删除申请已发出", {
                                icon: 1,
                                time: 1000
                            });
                            table.reload("test");
                        }
                    })
                }
                if (obj.event === 'del2') {
                    var id = data.id;
                    $.ajax({
                        url: '/mOverseeQuestions/deletePathTwo?id=' + id,
                        type: 'get',
                        success: function () {
                            layer.msg("删除成功", {
                                icon: 1,
                                time: 1000
                            });
                            table.reload("test");
                        }
                    })
                }
            });
        });

        // 附件下载
        function sleep(n) {
            var start = new Date().getTime();//定义起bai始时间的毫秒数
            while (true) {
                var time = new Date().getTime();//每次执行循环取得du一次当前时间的毫秒数
                if (time - start > n) {//如果当前时间的毫秒数减去起始时间的毫秒数大于给定的毫秒数，即结束循环
                    break;
                }
            }
        }

        function aa() {
            var ids = [];
            $.each($('input[name=\'childclick\']:checkbox'), function () {
                if (this.checked) {
                    ids.push($(this).val())
                }
            });
            if (ids.length === 0) {
                layer.msg('请选择数据查看');
                return
            }

            var url = "/mOverseeQuestions/downSource?id=" + encodeURI(JSON.stringify(ids));
            $.fileDownload(url, {
                httpMethod: 'GET',
                //同时上传表单数据
                data: '',
                prepareCallback: function (url) {
                    $('#down').attr('disabled', false)
                    console.log("请稍等！");
                },
                successCallback: function (url) {

                    $('#down').attr('disabled', false)
                    return false
                },
                failCallback: function (html, url) {
                    var json = JSON.parse(html);
                    console.log(json);
                    $('#down').attr('disabled', false)
                }
            });
            return false
        }

        $('#down').on('click', function () {
            aa()
        })
    })
    // 上传附件
    layui.use(['upload', 'form'], function () {

        var upload = layui.upload;
        var form = layui.form;

        //执行实例
        var uploadInst = upload.render({
            elem: '#btn2' //绑定元素
            , url: '/mOverseeQuestions/uploadSource' //上传接口
            , accept: 'file'
            , multiple: true
            , method: 'POST',
            data: {
                branch: $("#branch option:selected").text()
            },
            done: function (res) {
                //上传完毕回调
                layer.msg("上传成功！");
                $("#btn2").val(res.msg);
            }
            , error: function (res) {
                //请求异常回调
                layer.msg("上传失败！");
            }
        });
    });

    //刷新表单
    function renderForm() {
        layui.use('form', function () {
            var form = layui.form; //高版本建议把括号去掉，有的低版本，需要加()
            form.render();
        });
    }

    var branchUrl = "";
    var reviewerUrl = "";

    /*初始化下拉*/
    function setOption() {
        // 例如：new Option(item.xm, item.id)第一个参数是下拉列表中显示的值  第二个参数是选中传递给后台的值
        layui.use(['form', 'upload', 'layer'], function () {
                var year, questionKeyword, questionType, branch, schedule, sourceProblem, reviewer;
                var form = layui.form;

                /*单位*/
                branch = $.ajax({
                    url: branchUrl,
                    dataType: 'json',
                    type: 'post',
                    async: false,
                    success: function (data) {
                        // 使用循环遍历，给下拉列表赋值
                        $.each(data, function (index, value) {
                            $('#branch').append(new Option(value.value, value.key));// 下拉菜单里添加元素
                        });
                        form.render("select");//重新渲染 固定写法
                        console.log("单位");
                    }
                })
                    /*巡查年度*/
                    , year = $.ajax({
                    url: '/dropDown/getYear',
                    dataType: 'json',
                    type: 'post',
                    success: function (data) {
                        // 使用循环遍历，给下拉列表赋值
                        $.each(data, function (index, value) {
                            $('#year').append(new Option(value.value, value.value));// 下拉菜单里添加元素
                        });
                        form.render();//重新渲染 固定写法
                    }
                })
                    /*类别*/
                    , questionType = $.ajax({
                    url: '/dropDown/getQuestion',
                    dataType: 'json',
                    type: 'post',
                    async: false,
                    success: function (data) {
                        // 使用循环遍历，给下拉列表赋值
                        $.each(data, function (index, value) {
                            $('#questionType').append(new Option(value.value, value.value));// 下拉菜单里添加元素
                        });
                        form.render("select");//重新渲染 固定写法
                        console.log("类别");
                    }
                })
                    /*关键字*/
                    , questionKeyword = $.ajax({
                    url: '/dropDown/getQuestionKeyword',
                    dataType: 'json',
                    type: 'post',
                    async: false,
                    success: function (data) {
                        // 使用循环遍历，给下拉列表赋值
                        $.each(data, function (index, value) {
                            $('#questionKeyword').append(new Option(value.value, value.value));// 下拉菜单里添加元素
                        });
                        form.render("select");//重新渲染 固定写法
                        console.log("关键字");
                    }
                })
                    /*问题来源*/
                    , sourceProblem = $.ajax({
                    url: '/dropDown/getSourceProblem',
                    dataType: 'json',
                    type: 'post',
                    async: false,
                    success: function (data) {
                        // 使用循环遍历，给下拉列表赋值
                        $.each(data, function (index, value) {
                            $('#sourceProblem').append(new Option(value.value, value.value));// 下拉菜单里添加元素
                        });
                        form.render("select");//重新渲染 固定写法
                        console.log("问题来源");
                    }
                })
                    /*审核人*/
                    , reviewer = $.ajax({
                    url: reviewerUrl,
                    dataType: 'json',
                    type: 'post',
                    async: false,
                    success: function (data) {
                        if (data.length == 0) {
                            layer.msg("该公司没有审核人员！", {
                                icon: 2,
                                time: 1000
                            })
                        }
                        $("#reviewer").empty();
                        // 使用循环遍历，给下拉列表赋值
                        $.each(data, function (index, value) {
                            $('#reviewer').append(new Option(value.value, value.value));// 下拉菜单里添加元素
                        });
                        renderForm();//重新渲染 固定写法
                        console.log("审核人");
                    }
                })
                    /*进度*/
                    , schedule = $.ajax({
                    url: '/dropDown/getSchedule',
                    dataType: 'json',
                    type: 'post',
                    async: false,
                    success: function (data) {
                        // 使用循环遍历，给下拉列表赋值
                        $.each(data, function (index, value) {
                            $('#schedule').append(new Option(value.value, value.value));// 下拉菜单里添加元素
                        });
                        form.render("select");//重新渲染 固定写法
                        console.log("进度");
                    }
                })
                    , form.on('select(branch)', function () {
                    if ($("#branch option:selected").text() === null || $("#branch option:selected").text() === '') {
                        $('#btn2').attr('disabled', true)
                    } else {
                        $('#btn2').attr('disabled', false)
                    }
                });
                $.when(branch, year, questionType, questionKeyword, sourceProblem, reviewer, schedule).done(function () {
                    setFormValue()
                });
            }
        );
    }

    function setFormValue() {
        // 数据回显
        layui.use(['layer', 'form'], function () {
            var id = getUrlParam("id");
            if (id > 0) {
                $.ajax({
                    url: '/mOverseeQuestions/' + id,
                    type: 'get',
                    success: function (data) {
                        $("#question").val(data.question);
                        $("#questionId").val(data.questionId);
                        $("#questionDetail").val(data.questionDetail);
                        $("#remark").val(data.remark);
                        $("#startPatrolTime").val(data.startPatrolTime);
                        $("#liaison").val(data.liaison);
                        /*下拉*/
                        $("#branch").val(data.branchId);
                        $("#year").val(data.startPatrolTime);
                        $("#questionType").val(data.questionType);
                        $("#questionKeyword").val(data.questionKeyword);
                        $("#sourceProblem").val(data.sourceProblem);
                        $("#reviewer").val(data.reviewer);
                        renderForm();
                    }
                });
            }
        });
    }

    // 区域展开伸缩
    $('.title-container .layui-icon').click(function () {
        var thisIcon = $(this);
        if (thisIcon.hasClass("layui-icon-up")) {
            thisIcon.removeClass("layui-icon-up").addClass("layui-icon-down");
            thisIcon.parent().next().slideUp(200)
        } else {
            thisIcon.removeClass("layui-icon-down").addClass("layui-icon-up");
            thisIcon.parent().next().slideDown(200)
        }
    })

    function PanelInit() {
        init()
        setOption()
        recordsInit()
    }

    layui.use(['form', 'laydate'], function () {
        var laydate = layui.laydate;
        laydate.render({
            elem: '#startPatrolTime'
            , range: true,
            done: function (value, date, endDate) {

            }
        });
    });

    //监听提交
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;
        var id = getUrlParam("id");
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            // 单击之后提交按钮不可选,防止重复提交
            var DISABLED = 'layui-btn-disabled';
            // 增加样式
            $('.save').addClass(DISABLED);
            // 增加属性
            $('.save').attr('disabled', 'disabled');
            data.field.branchId = $("#branch option:selected").val();//获取文本 id: 以降序排列此列
            data.field.branch = $("#branch option:selected").text();//获取文本 id: 以降序排列此列
            data.field.questionKeyword = $("#questionKeyword option:selected").text();//获取文本
            data.field.questionType = $("#questionType option:selected").text();//获取文本
            data.field.sourceProblem = $("#sourceProblem option:selected").text();//获取文本
            data.field.startPatrolTime = $("#year option:selected").text();//获取文本
            data.field.questionId = id;
            data.field.file = $("#btn2").val();
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '/mOverseeQuestions/updateQuestion',
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify(data.field),
                success: function (res) {
                    console.log(res);
                    if (res.errorCode === 0) {
                        layer.msg("保存成功", {
                            icon: 1,
                            time: 1000
                        }, function () {
                            window.close();
                        });
                    }
                }
            })
            return false;
        });

        //审核同意
        form.on('submit(agreeBtn)', function (data) {
            // 单击之后提交按钮不可选,防止重复提交
            var DISABLED = 'layui-btn-disabled';
            // 增加样式
            $('.agree').addClass(DISABLED);
            // 增加属性
            $('.agree').attr('disabled', 'disabled');
            data.field.branchId = $("#branch option:selected").val();//获取文本 id: 以降序排列此列
            data.field.branch = $("#branch option:selected").text();//获取文本 id: 以降序排列此列
            data.field.questionKeyword = $("#questionKeyword option:selected").text();//获取文本
            data.field.questionType = $("#questionType option:selected").text();//获取文本
            data.field.sourceProblem = $("#sourceProblem option:selected").text();//获取文本
            data.field.startPatrolTime = $("#year option:selected").text();//获取文本
            data.field.questionId = id;
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '/mOverseeQuestions/agreeExamine',
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify(data.field),
                success: function (res) {
                    if (res.errorCode == 0) {
                        layer.msg("审核成功", {
                            icon: 1,
                            time: 1000
                        }, function () {
                            window.close();
                        });
                    } else {
                        layer.msg(res.errorMsg, function () {
                            window.close();
                        });
                    }
                }
            })
            return false;
        });

        //审核不同意
        form.on('submit(notAgreeBtn)', function (data) {
            if (data.field.auditOpinion == "" || data.field.auditOpinion == "undefined") {
                layer.msg('请填写审核意见！！！', {
                    icon: 5,
                    time: 1000
                }, function () {
                    window.close();
                });
                return false;
            }
            // 单击之后提交按钮不可选,防止重复提交
            var DISABLED = 'layui-btn-disabled';
            // 增加样式
            $('.disagree').addClass(DISABLED);
            // 增加属性
            $('.disagree').attr('disabled', 'disabled');
            data.field.questionId = getUrlParam("id");
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '/mOverseeQuestions/notAgreeExamine',
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify(data.field),
                success: function (res) {
                    if (res.errorCode == 0) {
                        layer.msg("审核成功", {
                            icon: 1,
                            time: 1000
                        }, function () {
                            window.close();
                        });
                    } else {
                        layer.msg(res.errorMsg, function () {
                            window.close();
                        });
                    }
                }
            })
            return false;
        });

    });

    layui.use('form', function () {
        var form = layui.form;
        form.render('select', 'scoreRuleForm')
    })

    function init() {
        var id = getUrlParam("id");
        $.ajax({
            type: 'POST',
            dataType: 'text',
            url: '/mOverseeQuestions/getStatus/' + id,
            success: function (data) {
                /*修改*/
                if ("2" === data) {
                    document.getElementById("dtTitle").innerText = "督察问题记录-编辑";
                    $('.sh').css('display', 'none');
                    $('.zgjd').css('display', 'none');
                    document.getElementById("btn4").style.display = "none";
                    document.getElementById("btn5").style.display = "none";
                    branchUrl = "/dropDown/getBranchByUserId";
                    reviewerUrl = '/dropDown/getUserName'
                }
                /*审核*/
                else if ("3" === data) {
                    document.getElementById("dtTitle").innerText = "督察问题记录-审核";
                    $('.xg').attr('disabled', 'disabled');
                    $('.zgjd').css('display', 'none');
                    document.getElementById("btn1").style.display = "none";
                    document.getElementById("btn2").style.display = "none";
                    branchUrl = "/dropDown/getBranch";
                    reviewerUrl = '/dropDown/getUserName'
                } else if ("0" === data) {
                    document.getElementById("dtTitle").innerText = "督察问题记录";
                    $('.xg').attr('disabled', 'disabled');
                    $('.sh').css('display', 'none');
                    $('.fk').css('display', 'none');
                    document.getElementById("btn1").style.display = "none";
                    document.getElementById("btn2").style.display = "none";
                    document.getElementById("btn4").style.display = "none";
                    document.getElementById("btn5").style.display = "none";
                }

            }
        })
    }


    // 表格初始化数据
    var records;

    function recordsInit() {
        records = $('#records').DataTable({
            "searching": false,
            "processing": false,
            "serverSide": true,
            'iDisplayLength': 5,
            "ordering": false,
            "language": {
                "url": "/js/plugin/datatables/Chinese.lang"
            },
            "ajax": {
                "url": "/questionRecords/list",
                "type": "get",
                "data": function (d) {
                    d.overseeQuestionId = getUrlParam("id");
                    d.type = 1;
                },

            },
            "dom": "<'dt-toolbar'r>t<'dt-toolbar-footer table-page-footer'<'table-bottom col-sm-10 col-xs-12 hidden-xs'i><'table-bottom col-xs-12 col-sm-10' p v>>",
            "columns": [
                {"data": "checkStatus", "defaultContent": ""},
                {"data": "createTime", "defaultContent": ""},
                {"data": "updateUser", "defaultContent": ""},
                {"data": "detail", "defaultContent": ""},

            ],
            "order": [[0, "asc"]]
        });
    }

    PanelInit()

</script>

</body>
</html>



